﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ComponentModel;

namespace jQube.Web.JSon.Serialization
{
    public sealed class JSonWriter : Stream
    {
        private StringBuilder buffer;

        public JSonWriter()
            : base()
        {
            this.buffer = new StringBuilder();
        }

        public override string ToString()
        {
            return this.buffer.ToString();
        }

        public override bool CanRead
        {
            get { return false; }
        }

        public override bool CanSeek
        {
            get { return false; }
        }

        public override bool CanWrite
        {
            get { return true; }
        }

        public void Write(string value)
        {
            this.buffer.Append(value);
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            this.Write(UTF8Encoding.UTF8.GetString(buffer, offset, count));
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            throw new NotImplementedException();
        }

        public override void SetLength(long value)
        {
            throw new NotImplementedException();
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            throw new NotImplementedException();
        }

        public override void Flush()
        {
            throw new NotImplementedException();
        }

        public override long Length
        {
            get { return this.buffer.Length; }
        }

        public override long Position
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
    }
}
